﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Maticsoft.Model;
namespace Maticsoft.BLL
{
	/// <summary>
	/// monthSupplayPlan
	/// </summary>
	public partial class monthSupplayPlan
	{
		private readonly Maticsoft.DAL.monthSupplayPlan dal=new Maticsoft.DAL.monthSupplayPlan();
		public monthSupplayPlan()
		{}
         /// <summary>
        /// 获取已生成月供应计划总数
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListMonthSupplyTotalCount(string strWhere)
        {
            return dal.GetListMonthSupplyTotalCount(strWhere);
        }
        public bool UpdatearrivalAddress(string add, string ids)
        {
            return dal.UpdatearrivalAddress(add, ids);
        }
        public bool UpdatearrivalAddresshs(string add, string ids)
        {
            return dal.UpdatearrivalAddresshs(add, ids);
        }
        
        /// <summary>
        /// 获取月供应计划内容列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListMonthSupplyInfo(string strWhere)
        {
            return dal.GetListMonthSupplyInfo(strWhere);
        }
        public bool Updateresult(int did)
        {
            return dal.Updateresult(did);
        }
         /// <summary>
        /// 更新当月计划状态
        /// </summary>
        /// <param name="ks"></param>
        /// <param name="js"></param>
        /// <returns></returns>
        public bool Updatedatestatus()
        {
            return dal.Updatedatestatus();
        }
         /// <summary>
        /// 获取数据列表，包含当月计划的配送入库量(innums)
        /// 注意出现"null"值现象
        /// </summary>
        public DataSet GetListInnums(string strWhere)
        {
            return dal.GetListInnums(strWhere);
        }
        public DataSet GetListlink(string strWhere)
        {
            return dal.GetListlink(strWhere);
        }
		#region  Method
        public bool Updateskd(string ids, string skstate, DateTime d)
        {
            return dal.Updateskd(ids, skstate, d);
        }
        public bool Updatedate(int type, int did)
        {
            return dal.Updatedate(type, did);
        }
        public bool deldate(int type, int did)
        {
            return dal.deldate(type, did);
        }
        public DataSet GetListnums(string strWhere)
        {
            return dal.GetListnums(strWhere);
        }
        public DataSet GetListnumshs(string strWhere)
        {
            return dal.GetListnumshs(strWhere);
        }
        public bool Updateuid(int uid, string ids)
        {
            if(uid!=0)
            return dal.Updateuid(uid, ids);
            else
                return dal.Updateuid(ids);
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int monthSupplyPlanId)
		{
			return dal.Exists(monthSupplyPlanId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Maticsoft.Model.monthSupplayPlan model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.monthSupplayPlan model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int monthSupplyPlanId)
		{
			
			return dal.Delete(monthSupplyPlanId);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string monthSupplyPlanIdlist )
		{
			return dal.DeleteList(monthSupplyPlanIdlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.monthSupplayPlan GetModel(int monthSupplyPlanId)
		{
			
			return dal.GetModel(monthSupplyPlanId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Maticsoft.Model.monthSupplayPlan GetModelByCache(int monthSupplyPlanId)
		{
			
			string CacheKey = "monthSupplayPlanModel-" + monthSupplyPlanId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(monthSupplyPlanId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Maticsoft.Model.monthSupplayPlan)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Maticsoft.Model.monthSupplayPlan> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}

        public List<Maticsoft.Model.monthSupplayPlan> DataTableToList(DataTable dt)
        {
            List<Maticsoft.Model.monthSupplayPlan> modelList = new List<Maticsoft.Model.monthSupplayPlan>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Maticsoft.Model.monthSupplayPlan model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Maticsoft.Model.monthSupplayPlan();
                    if (dt.Rows[n]["monthSupplyPlanId"] != null && dt.Rows[n]["monthSupplyPlanId"].ToString() != "")
                    {
                        model.monthSupplyPlanId = int.Parse(dt.Rows[n]["monthSupplyPlanId"].ToString());
                    }
                    if (dt.Rows[n]["supplyDate"] != null && dt.Rows[n]["supplyDate"].ToString() != "")
                    {
                        model.supplyDate = DateTime.Parse(dt.Rows[n]["supplyDate"].ToString());
                    }
                    if (dt.Rows[n]["supplyPlanId"] != null && dt.Rows[n]["supplyPlanId"].ToString() != "")
                    {
                        model.supplyPlanId = int.Parse(dt.Rows[n]["supplyPlanId"].ToString());
                    }
                    if (dt.Rows[n]["thisMonthCount"] != null && dt.Rows[n]["thisMonthCount"].ToString() != "")
                    {
                        model.thisMonthCount = decimal.Parse(dt.Rows[n]["thisMonthCount"].ToString());
                    }
                    if (dt.Rows[n]["goodsQualityStatus"] != null && dt.Rows[n]["goodsQualityStatus"].ToString() != "")
                    {
                        model.goodsQualityStatus = dt.Rows[n]["goodsQualityStatus"].ToString();
                    }
                    if (dt.Rows[n]["isGoodsQualityStatus"] != null && dt.Rows[n]["isGoodsQualityStatus"].ToString() != "")
                    {
                        if ((dt.Rows[n]["isGoodsQualityStatus"].ToString() == "1") || (dt.Rows[n]["isGoodsQualityStatus"].ToString().ToLower() == "true"))
                        {
                            model.isGoodsQualityStatus = true;
                        }
                        else
                        {
                            model.isGoodsQualityStatus = false;
                        }
                    }
                    if (dt.Rows[n]["goodsQualityStatusDate"] != null && dt.Rows[n]["goodsQualityStatusDate"].ToString() != "")
                    {
                        model.goodsQualityStatusDate = DateTime.Parse(dt.Rows[n]["goodsQualityStatusDate"].ToString());
                    }
                    if (dt.Rows[n]["sendStatus"] != null && dt.Rows[n]["sendStatus"].ToString() != "")
                    {
                        model.sendStatus = dt.Rows[n]["sendStatus"].ToString();
                    }
                    if (dt.Rows[n]["sendStatusDate"] != null && dt.Rows[n]["sendStatusDate"].ToString() != "")
                    {
                        model.sendStatusDate = DateTime.Parse(dt.Rows[n]["sendStatusDate"].ToString());
                    }
                    if (dt.Rows[n]["lastArrivalDate"] != null && dt.Rows[n]["lastArrivalDate"].ToString() != "")
                    {
                        model.lastArrivalDate = DateTime.Parse(dt.Rows[n]["lastArrivalDate"].ToString());
                    }
                    if (dt.Rows[n]["fristCheckedCount"] != null && dt.Rows[n]["fristCheckedCount"].ToString() != "")
                    {
                        model.fristCheckedCount = decimal.Parse(dt.Rows[n]["fristCheckedCount"].ToString());
                    }
                    if (dt.Rows[n]["lastCheckedDate"] != null && dt.Rows[n]["lastCheckedDate"].ToString() != "")
                    {
                        model.lastCheckedDate = DateTime.Parse(dt.Rows[n]["lastCheckedDate"].ToString());
                    }
                    if (dt.Rows[n]["instoreCount"] != null && dt.Rows[n]["instoreCount"].ToString() != "")
                    {
                        model.instoreCount = decimal.Parse(dt.Rows[n]["instoreCount"].ToString());
                    }
                    if (dt.Rows[n]["lastInstoreDate"] != null && dt.Rows[n]["lastInstoreDate"].ToString() != "")
                    {
                        model.lastInstoreDate = DateTime.Parse(dt.Rows[n]["lastInstoreDate"].ToString());
                    }
                    if (dt.Rows[n]["result"] != null && dt.Rows[n]["result"].ToString() != "")
                    {
                        model.result = dt.Rows[n]["result"].ToString();
                    }
                    if (dt.Rows[n]["arrivalAddress"] != null && dt.Rows[n]["arrivalAddress"].ToString() != "")
                    {
                        model.arrivalAddress = dt.Rows[n]["arrivalAddress"].ToString();
                    }
                    if (dt.Rows[n]["linkman"] != null && dt.Rows[n]["linkman"].ToString() != "")
                    {
                        model.linkman = dt.Rows[n]["linkman"].ToString();
                    }
                    if (dt.Rows[n]["contactWay"] != null && dt.Rows[n]["contactWay"].ToString() != "")
                    {
                        model.contactWay = dt.Rows[n]["contactWay"].ToString();
                    }
                    if (dt.Rows[n]["user_id"] != null && dt.Rows[n]["user_id"].ToString() != "")
                    {
                        model.user_id = int.Parse(dt.Rows[n]["user_id"].ToString());
                    }
                    if (dt.Rows[n]["status"] != null && dt.Rows[n]["status"].ToString() != "")
                    {
                        model.status = dt.Rows[n]["status"].ToString();
                    }
                    if (dt.Rows[n]["arrivalGoodsBillStatus"] != null && dt.Rows[n]["arrivalGoodsBillStatus"].ToString() != "")
                    {
                        model.arrivalGoodsBillStatus = dt.Rows[n]["arrivalGoodsBillStatus"].ToString();
                    }
                    if (dt.Rows[n]["arrivalGoodsBillTime"] != null && dt.Rows[n]["arrivalGoodsBillTime"].ToString() != "")
                    {
                        model.arrivalGoodsBillTime = DateTime.Parse(dt.Rows[n]["arrivalGoodsBillTime"].ToString());
                    }
                    if (dt.Rows[n]["isUpErp"] != null && dt.Rows[n]["isUpErp"].ToString() != "")
                    {
                        if ((dt.Rows[n]["isUpErp"].ToString() == "1") || (dt.Rows[n]["isUpErp"].ToString().ToLower() == "true"))
                        {
                            model.isUpErp = true;
                        }
                        else
                        {
                            model.isUpErp = false;
                        }
                    }
                    if (dt.Rows[n]["equipmentManage"] != null && dt.Rows[n]["equipmentManage"].ToString() != "")
                    {
                        model.equipmentManage = dt.Rows[n]["equipmentManage"].ToString();
                    }
                    if (dt.Rows[n]["createTime"] != null && dt.Rows[n]["createTime"].ToString() != "")
                    {
                        model.createTime = DateTime.Parse(dt.Rows[n]["createTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

